import net.spy.memcached.AddrUtil;
import net.spy.memcached.MemcachedClient;

import java.io.IOException;

/**
 * TODO:
 */
public class Benchmark {
    public static void main(String[] args) throws IOException {
        MemcachedClient c = new MemcachedClient(AddrUtil.getAddresses("10.28.7.24:11211 10.28.7.28:11211"));
        long start;

        //init key
        String[] ks = new String[10000];
        for (int i = 0; i < 10000; i++) {
            ks[i] = "k" + i;
        }

        //init data, 1kb
        int kb=1;
        byte[] bs = new byte[1024*kb];
        for(int i=0;i<1024*kb;i++){
            bs[i]=1;
        }
        String v = new String(bs);

        //set
        start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            c.set(ks[i], 3600, v);
        }
        System.out.println("[set]" + (System.currentTimeMillis() - start));

        //get
        start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            c.get(ks[i]);
        }
        System.out.println("[get]" + (System.currentTimeMillis() - start));

        //gets
        start = System.currentTimeMillis();
        c.getBulk(ks);
        System.out.println("[gets]" + (System.currentTimeMillis() - start));

        //delete
        start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            c.delete(ks[i]);
        }
        System.out.println("[delete]" + (System.currentTimeMillis() - start));

        c.shutdown();
    }
}
